package response

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

type Response struct {
	Code int         `json:"code"`
	Msg  interface{} `json:"msg"`
	Data interface{} `json:"data"`
}

const (
	ERROR   = 7
	SUCCESS = 0
)

func Result(code int, msg interface{}, data interface{}, c *gin.Context) {
	c.JSON(http.StatusOK, Response{
		Code: code,
		Msg:  msg,
		Data: data,
	})
}

func Ok(c *gin.Context) {
	Result(SUCCESS, "操作成功", map[string]interface{}{}, c)
}
func OkWithMessage(message string, c *gin.Context) {
	Result(SUCCESS, message, map[string]interface{}{}, c)
}

func OkWithData(data interface{}, c *gin.Context) {
	Result(SUCCESS, "查询成功", data, c)
}

func OkWithDetailed(data interface{}, message string, c *gin.Context) {
	Result(SUCCESS, message, data, c)
}

func Fail(c *gin.Context) {
	Result(ERROR, "操作失败", map[string]interface{}{}, c)
}

func FailWithMessage(message interface{}, c *gin.Context) {
	Result(ERROR, message, map[string]interface{}{}, c)
}

func FailWithDetailed(data interface{}, message interface{}, c *gin.Context) {
	Result(ERROR, message, data, c)
}
